/*
 *	Copyright © 2013 Changsha Shishuo Network Technology Co., Ltd. All rights reserved.
 *	长沙市师说网络科技有限公司 版权所有
 *	http://www.shishuo.com
 */

package com.hlingsoft.kkh.service;

import com.hlingsoft.kkh.dao.CheckInDao;
import com.hlingsoft.kkh.entity.CheckIn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 用户服务
 * 
 * @author Zhangjiale
 * 
 */
@Service
public class CheckInService {

	private SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
	@Autowired
	private CheckInDao checkInDao;

	// ///////////////////////////////
	// ///// 增加 ////////
	// ///////////////////////////////

	/**
	 * 增加用户
	 * 
	 * @param name
	 * @return User
	 * @throws java.text.ParseException
	 */
	public CheckIn checkInToday(long userId) throws ParseException {
		CheckIn checkIn = new CheckIn();
		checkIn.setUserId(userId);
		checkIn.setCheckInTime(sf.parse(sf.format(new Date())));
		checkInDao.addCheckIn(checkIn);
		return checkIn;
	}

	public boolean ifCheckInToday(long userId) throws ParseException {
		return checkInDao.getByIDAndTime(userId,
				sf.parse(sf.format(new Date()))) > 0;
	}
}
